package oop.main;



import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRadioButton;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;

/**
 * 
 * @author Chuck Heckman
 * 
 * This class will be used to display the main frame and
 * navigate to other Frames
 *
 */


 
public class MainFrame extends JFrame
{
        private static JRadioButton jrbPerson, jrbStudent, jrbEmployee;
        public static Person p1;
        public static Student s1;
        public static Employee e1;
        public JButton btnSubmit;
        public JButton btnCancel;
        public static JFrame frame;
       
        public static void main(String...arg)
        {
                MainFrame frame = new MainFrame();
                frame.setSize(500,200);
                frame.setLocationRelativeTo(null);
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setTitle("Person, Student, or Employee?");
                frame.setVisible(true);
        }
       
        public MainFrame()
        {
                JPanel jpRadioButtons = new JPanel();
                jpRadioButtons.setLayout(new GridLayout(3,1));
                jpRadioButtons.add(jrbPerson = new JRadioButton("Person"));
                jpRadioButtons.add(jrbStudent =new JRadioButton("Student"));
                jpRadioButtons.add(jrbEmployee = new JRadioButton("Employee"));
               
                JPanel jButtons = new JPanel();
                jButtons.setLayout(new GridLayout(1,2));
                jButtons.add(btnSubmit = new JButton("Submit"));
                jButtons.add(btnCancel = new JButton("Cancel"));
               
                add(jpRadioButtons, BorderLayout.WEST);
                add(jButtons, BorderLayout.SOUTH);
               
                ButtonGroup group = new ButtonGroup();
                group.add(jrbPerson);
                group.add(jrbStudent);
                group.add(jrbEmployee);
               
                jrbPerson.setMnemonic(KeyEvent.VK_P);
               
                jrbStudent.setMnemonic(KeyEvent.VK_S);
               
                jrbEmployee.setMnemonic(KeyEvent.VK_E);
               
               
                btnSubmit.addActionListener(new ActionListener()
                {
                        public void actionPerformed(ActionEvent e)
                        {
                                submitBtnClicked(e);
                        }
                });
               
 
                btnCancel.addActionListener(new ActionListener()
                {
                        public void actionPerformed(ActionEvent e)
                        {
                                cancelBtnClicked(e);
                        }
                });
       
        }
       
        private static void submitBtnClicked(ActionEvent e)
        {
                boolean valid = true;
                if (!jrbPerson.isSelected() && !jrbStudent.isSelected() && !jrbEmployee.isSelected())
                {
                        valid = false;
                }
               
                if(valid)
                {
                        if(jrbPerson.isSelected())
                        {
                                Person.main(null);
                        }
                        if(jrbStudent.isSelected())
                        {
                        		Student.main(null);
                        }
                        if(jrbEmployee.isSelected())
                        {
                                Employee.main(null);
                        }
                }
               
        }
       
        private static void cancelBtnClicked(ActionEvent e)
        {
        	System.exit(0);
        }
       
       
}